fix(ingestion): R1/R2 fences + R7/R9/R23 RPC hardening + R24e stage-FK removal#380
Merged
Merged
Conversation
Committed migration 20260708120000 (NOT applied to live — operator apply per docs/supabase-migration-reconciliation.md), schema.sql reconciled, drift manifest regenerated (13s scratch replay, clean). - R1/R2: complete_ingestion_job + fail_or_retry_ingestion_job take an optional p_worker_id lease fence. A worker reclaimed by a stale takeover now matches 0 rows and returns ok:false lease_lost instead of clobbering the reclaimer's newer state (indexed->failed, completed->pending). Backward compatible (p_worker_id defaults null); the worker passes workerId and treats lease_lost as a stop, keeping the isMissingSchemaError fallback for pre-apply. This is the defense-in-depth complement to the lease heartbeat already in this PR. - R7: fail_or_retry downgrades an attempt-exhausted retry to terminal 'failed' instead of a permanently-unclaimable 'pending' that pins its batch forever. - R9: refresh_import_batch_status locks the import_batches row before counting, serializing concurrent last-job refreshes (lost-update that stuck batches as 'processing'). - R23: cleanup_abandoned re-asserts the open-job guard immediately before the destructive deletes (it previously lived only in the candidate CTE, before the seven count statements). HELD (evidence in PR): R17 open-jobs unique index (collides with drift backlog #7, ingestion_jobs index reshape); R24e stage-FK removal (collides with drift backlog #8, which plans the opposite — live has 253 orphan rows that would fail VALIDATE); deep-memory delete-scoping (would crash — document_sections unique(document_id,section_index)). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Updates to Preview Branch (claude/ingestion-concurrency-rpc-fixes) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
BigSimmo
enabled auto-merge (squash)
July 8, 2026 06:55
… collision) 20260708120000 was already taken by 20260708120000_rag_query_misses_retention.sql on main; two migrations sharing a version fail the schema_migrations pkey on replay/apply. Content unchanged; schema.sql + drift manifest unaffected (manifest keys on schema.sql sha, not migration versions).
Owner
Author
Review — strong LGTMReviewed the migration + worker changes for correctness. Well-scoped and follows the migration-reconciliation discipline; only minor nits. Correctness confirmed
Findings
Nothing blocking; #1 is the only thing I'd change before merge. 🤖 Automated review by Claude Code |
This was referenced Jul 8, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the RPC-hardening subset of the phase-3 concurrency work-order (#377), off current main (which now carries the R11 janitor guard + R1 lease heartbeat from the merged #369). Follows
docs/ingestion-state-machine.md§8 anddocs/supabase-migration-reconciliation.md(expand/contract).Migration
20260708120000— NOT applied to live (operator apply step). schema.sql reconciled,drift-manifest.jsonregenerated via Docker (clean 13s scratch replay).complete_ingestion_job+fail_or_retry_ingestion_jobgain an optionalp_worker_id. A worker reclaimed by a stale takeover matches 0 rows → returnsok:false lease_lostinstead of clobbering the reclaimer's newer state (indexed→failed, completed→pending). Backward compatible (p_worker_iddefaults null, so today's 4-/8-arg calls still resolve) — the DB migration can ship before the worker redeploy; the worker passesworkerId, treatslease_lostas a clean stop, and keeps theisMissingSchemaErrorfallback for the pre-apply window. Defense-in-depth complement to the heartbeat now on main.failedinstead of a permanently-unclaimablependingthat pins the batch asprocessingforever.refresh_import_batch_statuslocks theimport_batchesrow before counting, serializing concurrent last-job refreshes (the lost-update that stuck batches).cleanup_abandoned_document_index_generationsre-asserts the open-job guard immediately before the destructive deletes (previously only in the candidate CTE, before the seven counts).Verified: eslint ✅ prettier ✅ tsc ✅ · vitest drift-detection + supabase-schema replay guards + ingestion (69 tests) ✅ ·
drift:manifestregenerated ✅.check:indexing/reindex:health/check:drift(live) and the migration apply are operator steps.Deliberately excluded (documented in the #377 work-order, with live evidence): R17 open-jobs unique index (drift backlog item #7 owns the
ingestion_jobsindex reshape; live is clean so it's safe whenever done there); R24e stage-FK (drift backlog item #8 plans to add it, but live has 253 orphans that would fail VALIDATE → evidence says remove — owner decision); deep-memory delete-scoping (would crash —document_sectionshasunique (document_id, section_index)).Refs #377 #369 #342
🤖 Generated with Claude Code